package com.luxsoft.siipap.em.dashboards;


import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.Action;

import org.jdesktop.swingx.JXTaskPaneContainer;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.luxsoft.siipap.swing.utils.MessageUtils;
import com.luxsoft.siipap.swing.views2.DefaultTaskDockingView;



public class DashBoardMainView extends DefaultTaskDockingView implements ApplicationContextAware{
	
	public DashBoardMainView(String name) {
		super(name);
	}

	private List<String> dashboards=new ArrayList<String>();
	
	

	@Override
	protected void instalarTaskPanels(JXTaskPaneContainer container) {		
		container.remove(operaciones);
		container.remove(filtros);
	}
	
	public void initDashboards(){
		getContent();// Inicializar el panel
		for(String id:dashboards){
			Action a=new ShowDashAction(id);
			configAction(a, id);
			consultas.add(a);
		}
	}
	
	

	protected void instalarTaskElements(){
		procesos.setExpanded(false);
	}
	
	private ApplicationContext context;

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.context=applicationContext;
		
	}

	public List<String> getDashboards() {
		return dashboards;
	}

	public void setDashboards(List<String> dashboards) {
		this.dashboards = dashboards;
	}
	
	
	private class ShowDashAction extends AbstractAction{
		
		private String dashBoardId;
		
		public ShowDashAction(final String dashBoardId){
			this.dashBoardId=dashBoardId;
		}

		public void actionPerformed(ActionEvent e) {
			try {
				AbstractDashboardControl control=(AbstractDashboardControl)context.getBean(dashBoardId);
				addPanel(control.getControl());
			} catch (NoSuchBeanDefinitionException e2) {
				MessageUtils.showMessage("No econtro el Dashboard con id:"+dashBoardId, "Dashboard nulo");
			}			
		}
		
	}

	
	

}
